//
//  SNKVideoPageController.m
//  SleepNews
//
//  Created by Kavee DJ on 2017/1/11.
//  Copyright © 2017年 Kavee DJ. All rights reserved.
//

#import "SNKVideoPageController.h"

#import "SNKVideoViewController.h"

@interface SNKVideoPageController ()


@property (nonatomic, weak) SNKVideoViewController *oldVC;
@property (nonatomic, strong) NSArray *titleArray;
@property (nonatomic, strong) NSMutableArray *vcArray;

@end

@implementation SNKVideoPageController

#pragma mark - 懒加载
- (NSArray *)titleArray {
    if (!_titleArray) {
        _titleArray = @[@"奇葩",@"萌宠",@"明星",@"娱乐",@"精品",@"搞笑",@"趣味"];
    }
    return _titleArray;
}

- (NSMutableArray *)vcArray {
    if (!_vcArray) {
        NSArray *urlArray = @[@"VAP4BFE3U",
                              @"VAP4BFR16",
                              @"VAP4BG6DL",
                              @"V9LG4CHOR",
                              @"VAP4BGTVD",
                              @"V9LG4E6VR",
                              @"00850FRB"];
        
        NSArray *nameArray = self.titleArray;
        
        _vcArray = [NSMutableArray array];
        for (NSInteger i = 0; i < nameArray.count; i++) {
            SNKVideoViewController *videoViewController = [[SNKVideoViewController alloc] init];
            videoViewController.title = nameArray[i];
            videoViewController.url = urlArray[i];
            [_vcArray addObject:videoViewController];
        }
    }
    return _vcArray;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navigationItem.title = @"视频";
}

#pragma mark - 数据源方法
- (NSInteger)numbersOfChildControllersInPageController:(WMPageController *)pageController {
    return self.titleArray.count;
}

- (UIViewController *)pageController:(WMPageController *)pageController viewControllerAtIndex:(NSInteger)index {
    return self.vcArray[index];
}

- (NSString *)pageController:(WMPageController *)pageController titleAtIndex:(NSInteger)index {
    return self.titleArray[index];
}

#pragma mark - 代理方法
- (void)pageController:(WMPageController *)pageController willEnterViewController:(__kindof UIViewController *)viewController withInfo:(NSDictionary *)info {
    _oldVC = (SNKVideoViewController *)self.currentViewController;
}

- (void)pageController:(WMPageController *)pageController didEnterViewController:(__kindof UIViewController *)viewController withInfo:(NSDictionary *)info {
    if (viewController == _oldVC) return;
    [self.oldVC finish];
}

@end
